package com.tang.hawkmusic.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.tang.hawkmusic.R;
import com.tang.hawkmusic.bean.PlaylistDTO;

import java.util.List;

public class PlayListAdapter extends RecyclerView.Adapter<PlayListAdapter.MyViewHolder> {

    private final Context context;
    private List<PlaylistDTO> playlistDTOS;

    public PlayListAdapter(Context context,List<PlaylistDTO> playlistDTOS) {
        this.context=context;
        this.playlistDTOS = playlistDTOS;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.card_one_playlist,parent,false);
        MyViewHolder myViewHolder= new MyViewHolder(view);
        return myViewHolder;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        PlaylistDTO playlist=playlistDTOS.get(position);
        Glide.with(context)
                .load(playlist.getCoverImgUrl())
                .into(holder.listImage);
        holder.listName.setText(playlist.getName());
        holder.musicCount.setText(playlist.getTrackCount().toString()+"首");
    }

    @Override
    public int getItemCount() {
        return playlistDTOS.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        public ImageView listImage;
        public TextView  listName;
        public TextView musicCount;
        public ImageView moreImage;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            listImage=itemView.findViewById(R.id.play_list_img);
            listName=itemView.findViewById(R.id.playlist_name);
            musicCount=itemView.findViewById(R.id.music_count);
            moreImage=itemView.findViewById(R.id.more_img);
        }
    }

    public void setPlaylistDTOS(List<PlaylistDTO> playlistDTOS) {
        this.playlistDTOS = playlistDTOS;
    }
}
